﻿using System;
using System.Windows.Forms;

namespace Amgine
{
    partial class AccountGroupEditForm : Form
    {
        private AccountGroup group;

        public AccountGroupEditForm(AccountGroup group)
        {
            InitializeComponent();
            this.group = (group == null ? new AccountGroup() : group);
        }

        private void AccountGroupEditForm_Load(object sender, EventArgs e)
        {
            textBox_name.Text = group.Title;
            textBox_remark.Text = group.Remark;
        }

        private void button_confirm_Click(object sender, EventArgs e)
        {
            group.Title = textBox_name.Text;
            group.Remark = textBox_remark.Text;
            if (validateData())
            {
                if (group.createOrUpdate())
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.Retry;
                }
                Close();
            }
        }

        private bool validateData()
        {
            if (string.IsNullOrWhiteSpace(group.Title))
            {
                MessageBox.Show("名称不可为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrWhiteSpace(group.Remark))
            {
                MessageBox.Show("备注不可为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return true;
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
